<template>
<div>
  <el-button @click="gundan">
    登录
  </el-button>
</div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import { Login } from '@/api'
export default {
  name: 'but',
  computed: {
    ...mapState(['username', 'password'])
  },
  methods: {
    ...mapMutations(['SET_TOKEN']),
    async gundan () {
      const { data: { data: res } } = await Login({ username: this.username, password: this.password })
      console.log(res)
      // 调用vuex
      this.SET_TOKEN(res.token)
      // 存缓存
      sessionStorage.setItem('z_token', res.token)
    }
  }
}
</script>

<style scoped>

</style>
